﻿Public Class ItemMaster
    Inherits System.Web.UI.Page
    Public oCompany As SAPbobsCOM.Company
    Dim connect As New Connection()
    Dim oItemMasterData As New ItemMasterData
    Dim Str As String = ""
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Try
        '    Dim oITM As SAPbobsCOM.Items
        '    Dim oRecordSetBP As SAPbobsCOM.Recordset
        '    oITM = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
        '    oRecordSetBP = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
        '    oRecordSetBP.DoQuery("(SELECT T1.[ItmsGrpNam] FROM [dbo].[OITB]  T1 ) UNION (SELECT  'SYSTEM'  [ItmsGrpNam] ) ORDER BY T1.[ItmsGrpNam]")
        '    Dim i As Integer

        '    If oRecordSetBP.RecordCount > 0 Then
        '        For i = 1 To oRecordSetBP.RecordCount
        '            ddlItemgroup.Items.Add(oRecordSetBP.Fields.Item(0).Value.ToString)
        '            oRecordSetBP.MoveNext()
        '        Next

        '    Else
        '        ddlItemgroup.Items.Add("SYSTEM")
        '    End If


        'Catch ex As Exception
        '    LAB.Text = ex.Message
        'End Try
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        Try
            If Connection.bConnect = False Then
                connect.setDB(Session("UserID"), Session("Pwd"))
                Dim Str As String = connect.connectDB()
                If Str = "" Then
                    CreateItemMasterData()
                Else
                    MsgBox(Str, MsgBoxStyle.OkOnly)
                    ' LAB.Text = Str
                    Exit Sub
                End If
            Else
                Dim str As String = Session("UserID")
                CreateItemMasterData()
                'Response.Redirect("../Default.aspx")
            End If
        Catch ex As Exception
            LAB.Text = ex.Message
        End Try
    End Sub

    Public Sub CreateItemMasterData()

        Try
            Dim Purch As String = ""
            Dim Sales As String = ""
            Dim Inv As String = ""
            If txtDescription.Text = "" Then
                LAB.Text = "Item Name Can't Be Empty!"
                Exit Sub
            Else
                If txtDescription.Text.Length > 100 Then
                    LAB.Text = "Item Name Can't Be Granter than 100 Characters!"
                    Exit Sub
                End If
            End If

            'If txtForeignName.Text.Length > 100 Then
            '    LAB.Text = "Item Name Can't Be Granter than 100 Characters!"
            '    Exit Sub
            'End If

            If ddlItemgroup.Text = "" Then
                LAB.Text = "Item Group Name Can't Be Empty!"
                Exit Sub
            End If
            If ChkInventoryitem.Checked = True Then
                Inv = "Y"
            Else
                Inv = "N"
            End If
            If ChkSalesitem.Checked = True Then
                Sales = "Y"
            Else
                Sales = "N"
            End If
            If ChkPuchaseitem.Checked = True Then
                Purch = "Y"
            Else
                Purch = "N"
            End If
            If Purch = "" And Sales = "" And Inv = "" Then
                LAB.Text = "Select one of the Inventory / Sales / Purchase Item Chek Box!"
                Exit Sub
            End If
            If Connection.bConnect = False Then
                connect.setDB(Session("UserID"), Session("Pwd"))
                Str = connect.connectDB()
                If Str = "" Then
                    Str = oItemMasterData.Item_Add(txtDescription.Text, ddlItemgroup0.Text, ddlItemgroup.Text, Purch, Sales, Inv, Session("UserID"))
                    If Str = "Item Created Successfully!" Then
                        LAB.ForeColor = Drawing.Color.Green
                        LAB.Text = Str
                        txtDescription.Text = ""
                        ' txtForeignName.Text = ""
                        ' TextBox3.Text = ""
                        LAB.ForeColor = Drawing.Color.Red
                    Else
                        LAB.ForeColor = Drawing.Color.Red
                        LAB.Text = Str
                    End If
                Else
                    LAB.Text = Str
                    Exit Sub
                End If
            Else

                Str = oItemMasterData.Item_Add(txtDescription.Text, ddlItemgroup0.Text, ddlItemgroup.Text, Purch, Sales, Inv, Session("UserID"))
                If Str = "Item Created Successfully!" Then
                    LAB.ForeColor = Drawing.Color.Green
                    LAB.Text = Str
                    txtDescription.Text = ""
                    'txtForeignName.Text = ""
                    ' TextBox3.Text = ""
                    LAB.ForeColor = Drawing.Color.Red
                Else
                    LAB.ForeColor = Drawing.Color.Red
                    LAB.Text = Str
                End If


            End If
        Catch ex As Exception
            LAB.Text = ex.Message
        End Try
        'Dim oITM As SAPbobsCOM.Items
        'Dim oITB As SAPbobsCOM.ItemGroups
        'oITM = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
        'oITB = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItemGroups)

    End Sub

    Protected Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        txtDescription.Text = ""
        ' txtForeignName.Text = ""
    End Sub
End Class